program main
    implicit none
    integer,parameter :: IDlen=10
    character(10),allocatable :: ID(:)
    !character,allocatable :: ID(:,:)
    real,allocatable :: grade(:,:)
    real :: ave(4)
    integer :: n,i,j,k
    
    !!!
    ! 输入数据
    write(*,*)'Number:'
    read(*,*) n
    !allocate(ID(n,IDlen))
    allocate(ID(n))
    allocate(grade(n,4))
    do i=1,n
        write(*,"(a3,i4)") "No.",i
        read(*,*) ID(i),grade(i,:)
    end do
    ! 计算均值
    ave=sum(grade,1)/real(n)
    write(*,"(50a1)")('=',k=1,50)
    write(*,"(a10,4a9)")"          ","  course1","  course2","  course3",&
    &"  course4"
    write(*,"(a10,4f9.2)")" average: ",ave
!    do i=1,n
!        write(*,"(a10,4f9.2)")ID(i),grade(i,:)
!    end do
    !输出成绩大于均值的人的学号和成绩
    do j=1,4 ! 按科目分类
        write(*,"(30a1)")('=',k=1,30)
        write(*,"(a10,a8,i1)")"    ID    ","  course",j
        do i=1,n
            if(grade(i,j)>ave(j))then! 遍历比较
                write(*,"(a10,f9.2)")ID(i),grade(i,j)
            end if
        end do
    end do
end program
